package com.mryan.server_system.configure;

import com.mryan.ps_common.handle.PSAccessDeniedHandler;
import com.mryan.ps_common.handle.PSAuthExceptionEntryPoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;

/**
 * @BelongsProject: ps_cloud
 * @BelongsPackage: com.mryan.server_system.configure
 * @Author: Yan
 * @CreateTime: 2021-04-25 19:06
 * @Description:
 */
@Configuration
@EnableResourceServer
public class PSServerSystemResourceServerConfigure extends ResourceServerConfigurerAdapter {

	@Autowired
	private PSAccessDeniedHandler psAccessDeniedHandler;
	@Autowired
	private PSAuthExceptionEntryPoint psAuthExceptionEntryPoint;

	@Override
	public void configure(HttpSecurity http) throws Exception {
		http.csrf().disable()
				.requestMatchers()
				.antMatchers("/**")
				.and()
				.authorizeRequests()
				.antMatchers("/**")
				.authenticated();
	}

	@Override
	public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
		resources.accessDeniedHandler(psAccessDeniedHandler)
				.authenticationEntryPoint(psAuthExceptionEntryPoint);
	}
}
